package com.mytijian.task.repository.database.utils;

import com.alibaba.fastjson.JSONObject;
import com.mytijian.task.enums.TaskTypeEnum;
import com.mytijian.task.model.SubTask;
import com.mytijian.task.model.Task;
import com.mytijian.task.repository.database.dao.daoobject.SubTaskDO;
import com.mytijian.task.repository.database.dao.daoobject.TaskDO;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class ModelUtils {
    public static TaskDO toTaskDO(Task task) {
        TaskDO taskDO = new TaskDO();
        BeanUtils.copyProperties(task, taskDO);
        taskDO.setType(task.getTaskTypeEnum().getCode());
        return taskDO;
    }
    public static List<SubTaskDO> toSubTaskDOs(List<SubTask> subTasks) {
        List<SubTaskDO> subTaskDOS = new ArrayList<>(subTasks.size());
        for (SubTask subTask : subTasks) {
            SubTaskDO subTaskDO = new SubTaskDO();
            BeanUtils.copyProperties(subTask, subTaskDO);
            subTaskDOS.add(subTaskDO);
        }
        return subTaskDOS;
    }
    public static List<Task> toTasks(List<TaskDO> taskDOS) {
        List<Task> tasks = new ArrayList<>(taskDOS.size());
        for (TaskDO taskDO : taskDOS) {
            Task task = new Task();
            BeanUtils.copyProperties(taskDO, task);
            task.setTaskTypeEnum(TaskTypeEnum.getByCode(taskDO.getType()));

            tasks.add(task);
        }
        return tasks;
    }
    public static List<SubTask> toSubTasks(List<SubTaskDO> subTaskDOS) {
        List<SubTask> list = new ArrayList<>(subTaskDOS.size());
        for (SubTaskDO subTaskDO : subTaskDOS) {
            SubTask subTask = new SubTask();
            BeanUtils.copyProperties(subTaskDO, subTask);
            list.add(subTask);
        }
        return list;
    }
}
